<template>
  <div class="main-content-wrapper d-flex flex-column">
    <!--头部-->
    <Top v-if="isLogin"/>
    <div class="content-page-box-area">
      <div class="row">
        <div class="col-lg-3 col-md-12">
          <aside class="widget-area">
            <HomeUserCard :user="user" v-if="isLogin"/>
            <HomeGroup v-if="isLogin"/>
          </aside>
        </div>
        <div class="col-lg-6 col-md-12">
            <HomeDynamic :user="user" v-if="isLogin"/>
        </div>
        <div class="col-lg-3 col-md-12">
            <HomeWeather v-if="isLogin"/>
        </div>
      </div>
    </div>
  </div>
  <!--  底部-->
  <Footer/>
</template>

<script setup>
import {ref, reactive, onMounted} from "vue";
import axios from '@/plugins/axios.js'
import router from "@/router/index.js";
import Top from "@/components/Top.vue";
import Footer from "@/components/Footer.vue";
import HomeUserCard from "@/components/HomeUserCard.vue";
import HomeGroup from "@/components/HomeGroup.vue";
import HomeDynamic from "@/components/HomeDynamic.vue";
import HomeWeather from "@/components/HomeWeather.vue";

//查询 用户信息
import loginUser from '@/stores/LoginUser.js'

let user;
let isLogin = ref(false)


let checkLogin=()=>{
    //如果 未登录,跳转到 登录页面
  user = loginUser().userModel;
  console.log(user.userInfo)
  if (user.uid !== -1){
    //已经登录
    isLogin.value = true
  }else {
    //自动登录
    axios.post("login/doUnameTokenLogin").then(result=>{
      if (result.code === 200){
        //登录成功
        loginUser().userModel = result.data;
        user = loginUser().userModel;
        isLogin.value = true;
      }else {
        //登录失败了
        //未登录,最后成功之后写,不然会再跳回登录页面
        router.push("/login")
      }
    })

  }
}

onMounted(() => {
  checkLogin();
});
</script>

<style scoped>

</style>